package com.smartstate.dataManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smartstate.dataManagement.dto.PageDTO;
import com.smartstate.dataManagement.entity.CarbonContribution;
import com.smartstate.dataManagement.mapper.ContributionMapper;
import com.smartstate.dataManagement.service.ContributionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ContributionImpl extends ServiceImpl<ContributionMapper, CarbonContribution> implements ContributionService {

    @Autowired
    ContributionMapper contributionMapper;
    @Override
    public Page<CarbonContribution> queryAllPageByDTO(PageDTO pageDTO) {
        Page page = new Page(pageDTO.getPage(), pageDTO.getSize());
        QueryWrapper<CarbonContribution> queryWrapper = new QueryWrapper<>();
        return contributionMapper.selectPage(page, queryWrapper);
    }

    @Override
    public boolean removeAssetById(int id) {
        int b = contributionMapper.deleteById(id);
        if (b == 1 ){
            return true;
        }
        return false;
    }

    /**
     * 判断这个时间月份是否在数据库已存在 如果存在就做修改
     * @param carbonContribution
     * @return
     */
    String s = "0";
    @Override
    public int getCarbon(CarbonContribution carbonContribution) {
        Integer data = contributionMapper.getData(carbonContribution.getDateContribution());
        if (data != 0){
            return 0;
        }
        return 1;
    }
}
